﻿namespace WMS6.Web.Inventory
{
    using System;
    using System.Collections.Generic;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoDetailServiceRef;
    using WMS6.Web.BaseInfoServiceRef;
    using WMS6.Web.InventoryMgtServiceRef;
    using WMS6.Web.UserControls;

    public class TransferDetail : BasePage
    {
        protected Button btnCancel;
        protected Button btnCopy;
        protected Button btnSave;
        protected HtmlAnchor ButtonA;
        protected DropDownList ddlFromUomID;
        protected DropDownList ddlToUomID;
        protected HtmlForm F5063;
        protected HtmlInputHidden hdnAllowChangeTransferQty;
        protected HtmlInputHidden hdncalendarFlag;
        protected HtmlInputHidden hdnDataFormat;
        protected HiddenField hdnExpiryDate;
        protected HiddenField hdnExpiryDate2;
        protected HiddenField hdnExternal;
        protected HiddenField hdnExternal2;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnFromOwnerID;
        protected HtmlInputHidden hdnFromSkuID;
        protected HtmlInputHidden hdnFromTransferQty;
        protected HiddenField hdnLot101;
        protected HiddenField hdnLot102;
        protected HiddenField hdnLot11;
        protected HiddenField hdnLot12;
        protected HiddenField hdnLot21;
        protected HiddenField hdnLot22;
        protected HiddenField hdnLot31;
        protected HiddenField hdnLot32;
        protected HiddenField hdnLot41;
        protected HiddenField hdnLot42;
        protected HiddenField hdnLot51;
        protected HiddenField hdnLot52;
        protected HiddenField hdnLot61;
        protected HiddenField hdnLot62;
        protected HiddenField hdnLot71;
        protected HiddenField hdnLot72;
        protected HiddenField hdnLot81;
        protected HiddenField hdnLot82;
        protected HiddenField hdnLot91;
        protected HiddenField hdnLot92;
        protected HtmlInputHidden hdnOriginQty;
        protected HiddenField hdnProductDate;
        protected HiddenField hdnProductDate2;
        protected HtmlInputHidden hdnToOriginQty;
        protected HtmlInputHidden hdnToOwnerID;
        protected HtmlInputHidden hdnToSkuID;
        protected HtmlInputHidden hdnTransferID;
        protected HtmlInputHidden hdnType;
        protected HiddenField hdnVendorID;
        protected HiddenField hdnVendorID2;
        protected Label lblFrom;
        protected Label lblFromLoc;
        protected Label lblFromLot;
        protected Label lblFromLpn;
        protected Label lblFromPackID;
        protected Label lblFromQty;
        protected Label lblFromReceiptDate;
        protected Label lblFromSkuDescr;
        protected Label lblFromSkuID;
        protected Label lblFromUomID;
        protected Label lblFromVendorID;
        protected Label lblLineID;
        protected Label lblMsg;
        protected Label lblStatus;
        protected Label lblTo;
        protected Label lblToLoc;
        protected Label lblToLot;
        protected Label lblToLpn;
        protected Label lblToPackID;
        protected Label lblToQty;
        protected Label lblToReceiptDate;
        protected Label lblToSkuDescr;
        protected Label lblToSkuID;
        protected Label lblToUomID;
        protected Label lblToVendorID;
        protected Label lblTransferDetail;
        protected LotAtrributeCtrl LotAtrributeCtrl1;
        protected LotAtrributeCtrl LotAtrributeCtrl2;
        protected HtmlLink mycss;
        protected Label one1;
        protected ScriptManager ScriptManager1;
        protected TextBox txtFromLoc;
        protected TextBox txtFromLot;
        protected TextBox txtFromLpn;
        protected TextBox txtFromPackID;
        protected TextBox txtFromQty;
        protected TextBox txtFromReceiptDate;
        protected TextBox txtFromSkuDescr;
        protected TextBox txtFromSkuID;
        protected TextBox txtFromVendorID;
        protected TextBox txtLineID;
        protected TextBox txtStatus;
        protected TextBox txtToLoc;
        protected TextBox txtToLot;
        protected TextBox txtToLpn;
        protected TextBox txtToPackID;
        protected TextBox txtToQty;
        protected TextBox txtToReceiptDate;
        protected TextBox txtToSkuDescr;
        protected TextBox txtToSkuID;
        protected TextBox txtToVendorID;
        protected UpdatePanel up1;

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            base.Response.Redirect(string.Format("Transfer.aspx?from={0}&detail={1}&ID={2}", base.UrlEncode(this.hdnFrom.Value), "1", base.UrlEncode(this.hdnTransferID.Value.Trim())));
        }

        protected void btnCopy_Click(object sender, EventArgs e)
        {
            this.txtToSkuID.Text = this.txtFromSkuID.Text.Trim();
            this.txtToSkuDescr.Text = this.txtFromSkuDescr.Text.Trim();
            this.txtToVendorID.Text = this.txtFromVendorID.Text.Trim();
            this.txtToLoc.Text = this.txtFromLoc.Text.Trim();
            this.txtToLot.Text = this.txtFromLot.Text.Trim();
            this.txtToLpn.Text = this.txtFromLpn.Text.Trim();
            this.txtToPackID.Text = this.txtFromPackID.Text.Trim();
            base.BindUomList2DDL(this.ddlToUomID, this.txtFromPackID.Text.Trim());
            this.txtToQty.Text = this.txtFromQty.Text.Trim();
            this.txtToReceiptDate.Text = this.txtFromReceiptDate.Text.Trim();
            this.SetLotValueToHdn(this.txtFromLot.Text, "1");
            this.SetLotValueToHdn(this.txtToLot.Text, "2");
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Exception ex;
            try
            {
                string temp;
                if (this.txtStatus.Text.ToUpper() != "NEW")
                {
                    base.ShowMsgLabel(this.lblMsg, base.GetGlobalMsgResource("F5300_013"));
                    return;
                }
                if (string.IsNullOrEmpty(this.txtToSkuID.Text) && string.IsNullOrEmpty(this.txtFromSkuID.Text))
                {
                    base.ShowMsgLabel(this.lblMsg, base.GetGlobalMsgResource("F5300_021"));
                    return;
                }
                if (decimal.Parse(this.txtFromQty.Text) <= 0M)
                {
                    base.ShowMsgLabel(this.lblMsg, "调整数量不能小于0!");
                    return;
                }
                if (string.IsNullOrEmpty(this.txtFromQty.Text.Trim()) || string.IsNullOrEmpty(this.txtToQty.Text.Trim()))
                {
                    base.ShowMsgLabel(this.lblMsg, base.GetGlobalMsgResource("F5300_014"));
                    return;
                }
                if (decimal.Parse(this.txtToQty.Text.Trim()) <= 0M)
                {
                    base.ShowMsgLabel(this.lblMsg, base.GetGlobalMsgResource("F5300_015"));
                    return;
                }
                if (!string.IsNullOrEmpty(this.hdnOriginQty.Value) && (decimal.Parse(this.hdnOriginQty.Value) < decimal.Parse(this.txtFromQty.Text)))
                {
                    base.ShowMsgLabel(this.lblMsg, "调整数量不能大于可用数量(" + this.hdnOriginQty.Value + ")!");
                    return;
                }
                if ((decimal.Parse(this.txtFromQty.Text) > decimal.Parse(this.hdnFromTransferQty.Value)) || (decimal.Parse(this.txtToQty.Text) > decimal.Parse(this.hdnFromTransferQty.Value)))
                {
                    base.ShowMsgLabel(this.lblMsg, string.Format(base.GetGlobalMsgResource("F5300_022"), this.hdnFromTransferQty.Value));
                    return;
                }
                if (string.IsNullOrEmpty(this.txtToLoc.Text.Trim()))
                {
                    base.ShowMsgLabel(this.lblMsg, base.GetGlobalMsgResource("F5300_016"));
                    return;
                }
                if (string.IsNullOrEmpty(this.txtToReceiptDate.Text.Trim()))
                {
                    base.ShowMsgLabel(this.lblMsg, base.GetGlobalMsgResource("F5300_017"));
                    return;
                }
                if (string.IsNullOrEmpty(this.txtFromSkuID.Text.Trim()))
                {
                    base.ShowMsgLabel(this.lblMsg, base.GetGlobalMsgResource("F5300_018"));
                    return;
                }
                TransferDetailInfo transferDetailInfo = new TransferDetailInfo {
                    TransferID = this.hdnTransferID.Value,
                    LineID = int.Parse(this.txtLineID.Text),
                    FromOwnerID = this.hdnFromOwnerID.Value,
                    FromSkuID = this.txtFromSkuID.Text.Trim(),
                    FromLoc = this.txtFromLoc.Text.Trim(),
                    FromLot = this.txtFromLot.Text.Trim(),
                    FromLpnID = this.txtFromLpn.Text.Trim(),
                    FromQty = decimal.Parse(this.txtFromQty.Text.Trim()),
                    FromPackID = this.txtFromPackID.Text.Trim(),
                    FromUomID = this.ddlFromUomID.SelectedValue,
                    ToOwnerID = this.hdnToOwnerID.Value,
                    ToSkuID = this.txtToSkuID.Text.Trim(),
                    ToLoc = this.txtToLoc.Text.Trim(),
                    ToLot = this.txtToLot.Text.Trim(),
                    ToLpnID = this.txtToLpn.Text.Trim()
                };
                if (this.hdnAllowChangeTransferQty.Value != "Y")
                {
                    this.txtToQty.Text = this.txtFromQty.Text.Trim();
                }
                transferDetailInfo.ToQty = decimal.Parse(this.txtToQty.Text.Trim());
                transferDetailInfo.ToPackID = this.txtToPackID.Text.Trim();
                transferDetailInfo.ToUomID = this.ddlToUomID.SelectedValue;
                transferDetailInfo.Status = this.txtStatus.Text;
                transferDetailInfo.Udf1 = this.hdnOriginQty.Value;
                ReceiptLotInfo transferLot = new ReceiptLotInfo();
                DateTime dt = DateTime.Now;
                transferLot.LotAttr01 = "";
                transferLot.LotAttr02 = "";
                transferLot.LotAttr03 = "";
                transferLot.LotAttr04 = "";
                transferLot.LotAttr05 = "";
                transferLot.LotAttr06 = "";
                transferLot.LotAttr07 = "";
                transferLot.LotAttr08 = "";
                transferLot.LotAttr09 = "";
                transferLot.LotAttr10 = this.hdnLot101.Value;
                List<Control> lotControls = this.Session["LotAttributeControls"] as List<Control>;
                this.Session["LotAttributeControls"] = null;
                if (lotControls != null)
                {
                    foreach (Control ctrl in lotControls)
                    {
                        DateTime CS00002;
                        object tempObj = base.Request.Form[this.LotAtrributeCtrl2.ClientID.ToString() + "$" + ctrl.ID.ToString()];
                        temp = "";
                        if (tempObj != null)
                        {
                            temp = tempObj.ToString();
                        }
                        if (ctrl.ID == "txtProduct")
                        {
                            try
                            {
                                if (string.IsNullOrEmpty(temp.Trim()))
                                {
                                    goto Label_093B;
                                }
                                CS00002 = new DateTime();
                                if (DateTime.Parse(temp) != CS00002)
                                {
                                    transferLot.ProduceDate = DateTime.Parse(temp);
                                    goto Label_093B;
                                }
                                this.lblMsg.Text = "输入的时间格式不正确！";
                                ctrl.Focus();
                            }
                            catch (Exception exception1)
                            {
                                ex = exception1;
                                this.lblMsg.Text = "输入的时间格式不正确！";
                                ctrl.Focus();
                            }
                            return;
                        }
                        else
                        {
                            if (ctrl.ID == "txtExpiryDate")
                            {
                                try
                                {
                                    if (string.IsNullOrEmpty(temp.Trim()))
                                    {
                                        goto Label_093B;
                                    }
                                    CS00002 = new DateTime();
                                    if (DateTime.Parse(temp) != CS00002)
                                    {
                                        transferLot.ExpiryDate = DateTime.Parse(temp);
                                        goto Label_093B;
                                    }
                                    this.lblMsg.Text = "输入的时间格式不正确！";
                                    ctrl.Focus();
                                }
                                catch (Exception exception2)
                                {
                                    ex = exception2;
                                    this.lblMsg.Text = "输入的时间格式不正确！";
                                    ctrl.Focus();
                                }
                                return;
                            }
                            if (ctrl.ID == "txtExternalLot")
                            {
                                if (!string.IsNullOrEmpty(temp))
                                {
                                    transferLot.ExternalLot = temp;
                                }
                                else
                                {
                                    transferLot.ExternalLot = "";
                                }
                            }
                            else
                            {
                                switch (ctrl.ID.Substring(4))
                                {
                                    case "1":
                                        transferLot.LotAttr01 = temp;
                                        goto Label_093B;

                                    case "2":
                                        transferLot.LotAttr02 = temp;
                                        goto Label_093B;

                                    case "3":
                                        transferLot.LotAttr03 = temp;
                                        goto Label_093B;

                                    case "4":
                                        transferLot.LotAttr04 = temp;
                                        goto Label_093B;

                                    case "5":
                                        transferLot.LotAttr05 = temp;
                                        goto Label_093B;

                                    case "6":
                                        transferLot.LotAttr06 = temp;
                                        goto Label_093B;

                                    case "7":
                                        transferLot.LotAttr07 = temp;
                                        goto Label_093B;

                                    case "8":
                                        transferLot.LotAttr08 = temp;
                                        goto Label_093B;

                                    case "9":
                                        transferLot.LotAttr09 = temp;
                                        goto Label_093B;

                                    case "10":
                                        transferLot.LotAttr10 = temp;
                                        goto Label_093B;
                                }
                            }
                        }
                    Label_093B:;
                    }
                }
                transferLot.ReceiptDate = string.IsNullOrEmpty(this.txtToReceiptDate.Text.Trim()) ? new DateTime() : DateTime.Parse(this.txtToReceiptDate.Text.Trim());
                transferLot.VendorID = this.txtToVendorID.Text.Trim();
                transferDetailInfo.TransferLotInfo = transferLot;
                transferDetailInfo.TransferDate = DateTime.Now;
                transferDetailInfo.CreatedBy = base.UserInfo.UserID;
                transferDetailInfo.UpdatedBy = base.UserInfo.UserID;
                if ((this.hdnType.Value != "") && (this.hdnType.Value.ToUpper() == "EDIT"))
                {
                    temp = InventoryMgtServiceClientProxy.GetInstance().UpdateTransferDetail(transferDetailInfo);
                    this.lblMsg.Text = temp + base.GetGlobalMsgResource("C002");
                }
                else
                {
                    temp = InventoryMgtServiceClientProxy.GetInstance().InsertTransferDetailInfo(transferDetailInfo);
                    this.lblMsg.Text = temp + base.GetGlobalMsgResource("C004");
                }
            }
            catch (Exception exception3)
            {
                ex = exception3;
                this.lblMsg.Text = base.GetGlobalMsgResource("F5300_019") + ex.Message;
                return;
            }
            base.Response.Redirect(string.Format("Transfer.aspx?from={0}&detail={1}&ID={2}", base.UrlEncode(this.hdnFrom.Value), "2", base.UrlEncode(this.hdnTransferID.Value.Trim())));
        }

        protected void ButtonA_Click(object sender, EventArgs e)
        {
            string[] rtnValus = this.hdnFromSkuID.Value.Split(new char[] { ',' });
            this.txtFromLot.Text = rtnValus[0];
            this.txtFromLoc.Text = rtnValus[1];
            this.txtFromLpn.Text = rtnValus[2];
            this.txtFromSkuID.Text = rtnValus[3];
            this.hdnFromSkuID.Value = rtnValus[3];
            this.txtFromSkuDescr.Text = rtnValus[4];
            this.txtFromQty.Text = base.GetPreferenceDigit(rtnValus[5]);
            this.hdnOriginQty.Value = rtnValus[5];
            this.txtFromPackID.Text = rtnValus[6];
            this.txtFromLot_OnTextChanged(null, null);
            this.txtFromPackID_OnTextChanged(null, null);
            this.hdnFromTransferQty.Value = this.txtFromQty.Text;
        }

        private void LoadData()
        {
            this.hdnType.Value = "new";
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"]))
            {
                this.hdnTransferID.Value = base.Request.QueryString["ID"].ToString();
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["SeqNO"]))
            {
                this.txtLineID.Text = base.Request.QueryString["SeqNO"].ToString();
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["FOwnerID"]))
            {
                this.hdnFromOwnerID.Value = base.Request.QueryString["FOwnerID"].ToString();
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["TOwnerID"]))
            {
                this.hdnToOwnerID.Value = base.Request.QueryString["TOwnerID"].ToString();
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            if (base.Request.QueryString["type"] != null)
            {
                this.hdnType.Value = base.Request.QueryString["type"].ToString();
                this.SetTransferDetail2From();
            }
            else
            {
                this.txtStatus.Text = "New";
            }
            SysSettingInfo sysSetting = BaseInfoServiceClientProxy.GetInstance().GetInfoByID("AllowChangeTransferQty", "SYS_SETTING") as SysSettingInfo;
            if (sysSetting != null)
            {
                this.hdnAllowChangeTransferQty.Value = sysSetting.Value;
                if (this.hdnAllowChangeTransferQty.Value != "Y")
                {
                    this.txtToQty.Enabled = false;
                }
            }
            if (this.txtStatus.Text.ToUpper() == "CONFIRMED")
            {
                this.btnCopy.Enabled = false;
                this.btnSave.Enabled = false;
            }
        }

        private void LoadLotAttributeInfoByID(string lotID, string flag)
        {
            try
            {
                LotAttributeInfo lotAttributeInfo = InventoryMgtServiceClientProxy.GetInstance().GetLotAttributeInfoByID(lotID);
                if (lotAttributeInfo != null)
                {
                    if (flag.ToUpper() == "FROM")
                    {
                        this.hdnExternal.Value = lotAttributeInfo.ExternalLot;
                    }
                    else if (flag.ToUpper() == "TO")
                    {
                        this.hdnExternal2.Value = lotAttributeInfo.ExternalLot;
                    }
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
            this.LotAtrributeCtrl1.LoadData(this.hdnFromSkuID.Value, this.hdnFromOwnerID.Value, this.LotAtrributeCtrl1.ClientID, false, 1);
            this.LotAtrributeCtrl2.LoadData(this.hdnToSkuID.Value, this.hdnToOwnerID.Value, this.LotAtrributeCtrl2.ClientID, true, 1);
        }

        private void SetLotValueToHdn(string LotID, string strFlag)
        {
            if (!string.IsNullOrEmpty(LotID))
            {
                LotAttributeInfo lotAttribute = InventoryMgtServiceClientProxy.GetInstance().GetLotAttributeInfoByID(LotID);
                if (lotAttribute != null)
                {
                    if (strFlag == "1")
                    {
                        this.hdnLot11.Value = lotAttribute.LotAttr01;
                        this.hdnLot21.Value = lotAttribute.LotAttr02;
                        this.hdnLot31.Value = lotAttribute.LotAttr03;
                        this.hdnLot41.Value = lotAttribute.LotAttr04;
                        this.hdnLot51.Value = lotAttribute.LotAttr05;
                        this.hdnLot61.Value = lotAttribute.LotAttr06;
                        this.hdnLot71.Value = lotAttribute.LotAttr07;
                        this.hdnLot81.Value = lotAttribute.LotAttr08;
                        this.hdnLot91.Value = lotAttribute.LotAttr09;
                        this.hdnLot101.Value = lotAttribute.LotAttr10;
                        this.hdnVendorID.Value = lotAttribute.VendorID;
                        this.hdnProductDate.Value = base.GetPreferenceShortDate(lotAttribute.ProduceDate);
                        this.hdnExpiryDate.Value = base.GetPreferenceShortDate(lotAttribute.ExpiryDate);
                        this.hdnExternal.Value = lotAttribute.ExternalLot;
                        this.txtFromReceiptDate.Text = base.GetPreferenceShortDate(lotAttribute.ReceiptDate);
                    }
                    else if (strFlag == "2")
                    {
                        this.hdnLot12.Value = lotAttribute.LotAttr01;
                        this.hdnLot22.Value = lotAttribute.LotAttr02;
                        this.hdnLot32.Value = lotAttribute.LotAttr03;
                        this.hdnLot42.Value = lotAttribute.LotAttr04;
                        this.hdnLot52.Value = lotAttribute.LotAttr05;
                        this.hdnLot62.Value = lotAttribute.LotAttr06;
                        this.hdnLot72.Value = lotAttribute.LotAttr07;
                        this.hdnLot82.Value = lotAttribute.LotAttr08;
                        this.hdnLot92.Value = lotAttribute.LotAttr09;
                        this.hdnLot102.Value = lotAttribute.LotAttr10;
                        this.hdnVendorID2.Value = lotAttribute.VendorID;
                        this.hdnProductDate2.Value = base.GetPreferenceShortDate(lotAttribute.ProduceDate);
                        this.hdnExpiryDate2.Value = base.GetPreferenceShortDate(lotAttribute.ExpiryDate);
                        this.hdnExternal2.Value = lotAttribute.ExternalLot;
                        this.txtToReceiptDate.Text = base.GetPreferenceShortDate(lotAttribute.ReceiptDate);
                    }
                }
            }
        }

        private void SetTransferDetail2From()
        {
            try
            {
                TransferDetailInfo transferDetail = InventoryMgtServiceClientProxy.GetInstance().GetTransferDetailByID(this.hdnTransferID.Value, this.txtLineID.Text);
                if (transferDetail != null)
                {
                    this.txtStatus.Text = transferDetail.Status;
                    this.txtFromSkuID.Text = transferDetail.FromSkuID;
                    this.txtToSkuID.Text = transferDetail.ToSkuID;
                    this.txtFromSkuDescr.Text = transferDetail.FromSkuDescr;
                    this.txtToSkuDescr.Text = transferDetail.ToSkuDescr;
                    this.txtToVendorID.Text = transferDetail.TransferLotInfo.VendorID;
                    this.txtFromLoc.Text = transferDetail.FromLoc;
                    this.txtToLoc.Text = transferDetail.ToLoc;
                    this.txtFromLot.Text = transferDetail.FromLot;
                    this.txtToLot.Text = transferDetail.ToLot;
                    this.txtFromLpn.Text = transferDetail.FromLpnID;
                    this.txtToLpn.Text = transferDetail.ToLpnID;
                    this.txtFromPackID.Text = transferDetail.FromPackID;
                    this.txtToPackID.Text = transferDetail.ToPackID;
                    this.hdnOriginQty.Value = transferDetail.Udf1;
                    if (!string.IsNullOrEmpty(this.txtFromPackID.Text.Trim()))
                    {
                        base.BindUomList2DDL(this.ddlFromUomID, this.txtFromPackID.Text.Trim());
                        this.ddlFromUomID.SelectedValue = transferDetail.FromUomID;
                    }
                    if (!string.IsNullOrEmpty(this.txtToPackID.Text.Trim()))
                    {
                        base.BindUomList2DDL(this.ddlToUomID, this.txtToPackID.Text.Trim());
                        this.ddlToUomID.SelectedValue = transferDetail.ToUomID;
                    }
                    this.txtFromQty.Text = base.GetPreferenceDigit(transferDetail.FromQty);
                    this.txtToQty.Text = base.GetPreferenceDigit(transferDetail.ToQty);
                    this.LotAtrributeCtrl1.LoadData(this.txtFromSkuID.Text, this.hdnFromOwnerID.Value, this.LotAtrributeCtrl1.ClientID, false, 1);
                    this.LotAtrributeCtrl2.LoadData(this.txtToSkuID.Text, this.hdnToOwnerID.Value, this.LotAtrributeCtrl2.ClientID, true, 1);
                    this.txtFromLot_OnTextChanged(null, null);
                    this.txtToLot_OnTextChanged(null, null);
                    InvLotLocLpnInfo invLotLocLpnInfo = InventoryMgtServiceClientProxy.GetInstance().GetInvLotLocLpnByID(transferDetail.FromLot, transferDetail.FromLoc, transferDetail.FromLpnID);
                    if (invLotLocLpnInfo != null)
                    {
                        decimal availableQty = (((invLotLocLpnInfo.Qty - invLotLocLpnInfo.AllocatedQty) - invLotLocLpnInfo.PickedQty) - invLotLocLpnInfo.ExpectedQty) - invLotLocLpnInfo.PickinprocessQty;
                        this.hdnFromTransferQty.Value = base.GetPreferenceDigit(availableQty);
                    }
                    else
                    {
                        this.hdnFromTransferQty.Value = base.GetPreferenceDigit(transferDetail.FromQty);
                    }
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
        }

        protected void txtFromLot_OnTextChanged(object sender, EventArgs e)
        {
            this.LotAtrributeCtrl1.LoadData(this.hdnFromSkuID.Value, this.hdnFromOwnerID.Value, this.LotAtrributeCtrl1.ClientID, false, 1);
            this.LoadLotAttributeInfoByID(this.txtFromLot.Text.Trim(), "From");
            this.SetLotValueToHdn(this.txtFromLot.Text, "1");
            this.SetLotValueToHdn(this.txtToLot.Text, "2");
        }

        protected void txtFromPackID_OnTextChanged(object sender, EventArgs e)
        {
            try
            {
                base.BindUomList2DDL(this.ddlFromUomID, this.txtFromPackID.Text.Trim());
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F5300_020") + ex.Message;
                this.txtFromPackID.Focus();
            }
        }

        protected void txtFromQty_TextChanged(object sender, EventArgs e)
        {
            this.lblMsg.Text = string.Empty;
            this.txtFromQty.Text = base.GetPreferenceDigit(this.txtFromQty.Text.Trim());
            if (decimal.Parse(this.txtFromQty.Text) > decimal.Parse(this.hdnFromTransferQty.Value))
            {
                this.lblMsg.Text = string.Format(base.GetGlobalMsgResource("F5300_022"), this.hdnFromTransferQty.Value);
            }
            if (this.hdnAllowChangeTransferQty.Value != "Y")
            {
                this.txtToQty.Text = this.txtFromQty.Text;
            }
        }

        protected void txtFromSkuID_TextChanged(object sender, EventArgs e)
        {
            this.hdnFromSkuID.Value = this.txtFromSkuID.Text.Trim();
            this.LotAtrributeCtrl1.LoadData(this.hdnFromSkuID.Value, this.hdnFromOwnerID.Value, this.LotAtrributeCtrl1.ClientID, true, 1);
            this.LotAtrributeCtrl2.LoadData(this.hdnToSkuID.Value, this.hdnToOwnerID.Value, this.LotAtrributeCtrl2.ClientID, true, 1);
        }

        protected void txtToLot_OnTextChanged(object sender, EventArgs e)
        {
            this.LoadLotAttributeInfoByID(this.txtFromLot.Text.Trim(), "To");
            this.SetLotValueToHdn(this.txtFromLot.Text, "1");
            this.SetLotValueToHdn(this.txtToLot.Text, "2");
        }

        protected void txtToPackID_OnTextChanged(object sender, EventArgs e)
        {
            try
            {
                base.BindUomList2DDL(this.ddlToUomID, this.txtToPackID.Text.Trim());
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F5300_020") + ex.Message;
                this.txtToPackID.Focus();
            }
        }

        protected void txtToSkuID_TextChanged(object sender, EventArgs e)
        {
            this.hdnToSkuID.Value = this.txtToSkuID.Text.Trim();
            try
            {
                string skuID = this.txtToSkuID.Text.Trim();
                if (string.IsNullOrEmpty(skuID))
                {
                    this.txtToSkuDescr.Text = "";
                    this.txtToPackID.Text = "";
                    this.ddlToUomID.Items.Clear();
                }
                else
                {
                    SkuInfo skuInfo = BaseInfoDetailServiceClientProxy.GetInstance().GetDetailInfoByID(this.hdnToOwnerID.Value, skuID, "", "SKU") as SkuInfo;
                    if (((skuInfo != null) && !string.IsNullOrEmpty(skuInfo.SkuID)) && !string.IsNullOrEmpty(skuInfo.OwnerID))
                    {
                        this.txtToSkuDescr.Text = skuInfo.Descr;
                        this.txtToPackID.Text = skuInfo.PackID;
                        base.BindUomList2DDL(this.ddlToUomID, this.txtToPackID.Text.Trim());
                        if (this.hdnAllowChangeTransferQty.Value != "Y")
                        {
                            this.txtToQty.Text = this.txtFromQty.Text;
                        }
                    }
                    else
                    {
                        this.lblMsg.Text = base.GetGlobalMsgResource("F4100_031");
                        this.txtToSkuID.Focus();
                    }
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
                this.txtToSkuID.Focus();
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>CloseSearch();false;</script>", false);
            }
        }
    }
}

